home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BKISSSRC.ZIP / LOADER / XDETECT.ASM < prev   
Encoding:
Assembly Source File  |  1993-12-13  |  4.0 KB  |  131 lines

  1. i86       equ 0
  2. i186      equ 1
  3. i286      equ 2
  4. i386sx    equ 3
  5. i386dx    equ 4
  6.  
  7. NONE      equ 0
  8. MDA       equ 1
  9. CGA       equ 2
  10. EGAMono   equ 3
  11. EGAColor  equ 4
  12. VGAMono   equ 5
  13. VGAColor  equ 6
  14. MCGAMono  equ 7
  15. MCGAColor equ 8
  16.  
  17. PS2_CARDS db  0,1,2,2,4,3,2,5,6,2,8,7,8
  18.  
  19. ;-----------------------------------------------------------------------
  20. ; PC Graphics detection routine. Returns graphics card type
  21. ;
  22. ; C callable as:
  23. ;    unsigned int x_graphics_card();
  24. ;
  25. ;
  26.  
  27. proc _x_graphics_card
  28.     mov  ax,1A00h            ; Try calling VGA Identity Adapter function
  29.     int  10h
  30.     cmp  al,1Ah              ; Do we have PS/2 video bios ?
  31.     jne  @@not_PS2           ; No!
  32.  
  33.     cmp  bl,0Ch              ; bl > 0Ch => CGA hardware
  34.     jg   @@is_CGA            ; Jump if we have CGA
  35.     xor  bh,bh
  36.     xor  ah,ah
  37.     mov  al,[cs:PS2_CARDS+bx] ; Load ax from PS/2 hardware table
  38.     jmp  short @@done        ; return ax
  39. @@is_CGA:
  40.     mov  ax,CGA              ; Have detected CGA, return id
  41.     jmp  short @@done
  42. @@not_PS2:                       ; OK We don't have PS/2 Video bios
  43.     mov  ah,12h              ; Set alternate function service
  44.     mov  bx,10h              ; Set to return EGA information
  45.     int  10h                 ; call video service
  46.     cmp  bx,10h              ; Is EGA there ?
  47.     je   @@simple_adapter    ; Nop!
  48.     mov  ah,12h              ; Since we have EGA bios, get details
  49.     mov  bl,10h
  50.     int  10h
  51.     or   bh,bh               ; Do we have colour EGA ?
  52.     jz   @@ega_color         ; Yes
  53.     mov  ax,EGAMono          ; Otherwise we have Mono EGA
  54.     jmp  short @@done
  55. @@ega_color:
  56.     mov  ax,EGAColor         ; Have detected EGA Color, return id
  57.     jmp  short @@done
  58. @@simple_adapter:
  59.     int  11h                 ; Lets try equipment determination service
  60.     and  al,30h
  61.     shr  al,4
  62.     xor  ah,ah
  63.     or   al,al               ; Do we have any graphics card at all ?
  64.     jz   @@done              ; No ? This is a stupid machine!
  65.     cmp  al,3                ; Do We have a Mono adapter
  66.     jne  @@is_CGA            ; No
  67.     mov  ax,MDA              ; Have detected MDA, return id
  68. @@done:
  69.     ret
  70. endp    _x_graphics_card
  71.  
  72.  
  73. ;-----------------------------------------------------------------------
  74. ; PC Processor detection routine
  75. ;
  76. ; C callable as:
  77. ;    unsigned int x_processor();
  78. ;
  79. ;
  80. proc _x_processor
  81.         pushf                    ; Save flags
  82.  
  83.         ;8086 detection
  84.         xor  ax,ax               ; Clear AX
  85.         push ax                  ; Push it on the stack
  86.         popf                     ; Zero the flags
  87.         pushf                    ; Try to zero bits 12-15
  88.         pop  ax                  ; Recover flags
  89.         and  ax,0F000h           ; If bits 12-15 are 1 => i86 or i286
  90.         cmp  ax,0F000h
  91.         jne  @@1
  92.  
  93.         ;80186 detection
  94.         push cx                  ; save CX
  95.         mov  ax,0FFFFh           ; Set all AX bits
  96.         mov  cl,33               ; Will shift once on 80186
  97.         shl  ax,cl               ; or 33 x on 8086
  98.         pop  cx
  99.         mov  ax,i186
  100.         jnz  @@done
  101.         mov  ax,i86              ; 0 => 8086/8088
  102.         jmp  short @@done
  103.  
  104. @@1:    ;80286 detection
  105.         mov  ax,07000h           ; Try to set bits 12-14
  106.         push ax
  107.         popf
  108.         pushf
  109.         pop  ax
  110.         and  ax,07000h           ; If bits 12-14 are 0 => i286
  111.         mov  ax,i286
  112.         jz   @@done
  113.  
  114. p386        
  115.         ;80386 detection
  116.         mov  eax,cr0
  117.         mov  ebx,eax                 ;Original CR0 into EBX
  118.         or   al,10h                  ;Set bit
  119.         mov  cr0,eax                 ;Store it
  120.         mov  eax,cr0                 ;Read it back
  121.         mov  cr0,ebx                 ;Restore CR0
  122.         test al,10h                  ;Did it set?
  123.         mov  ax,i386sx
  124.         jz   @@done                  ;Jump if 386SX
  125.         mov  ax,i386dx               ;assume it's 386dx or higher
  126. p286
  127.  
  128. @@done: popf
  129.         ret
  130. endp    _x_processor
  131.